<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>漫鸽笔记Markdown编辑器v0.1</title>
    <link rel="stylesheet" href="../static/plugin/layui/css/layui.css?v=1" media="all">
    <link rel="stylesheet" href="../static/css/md.css?v=2" media="all">
    <script src="../static/plugin/layui/layui.js?v=1"></script>
    <script src="../static/js/jquery-3.3.1.min.js?v=1"></script> 
    <script src="../static/plugin/editor.md-master/lib/marked.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/lib/prettify.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/lib/raphael.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/lib/underscore.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/lib/sequence-diagram.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/lib/flowchart.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/lib/jquery.flowchart.min.js?v=1"></script>
    <script src="../static/plugin/editor.md-master/editormd.js?v=1"></script>
    <script src="../static/js/man.js?v=2"></script> 
    <style type="text/css">
    pre{ 
        white-space:pre-wrap; 
        white-space:-moz-pre-wrap; 
        white-space:-pre-wrap; 
        white-space:-o-pre-wrap; 
        word-wrap:break-word; 
    } 
    p {
        word-break:break-word;
    }

  .scrollbar {
  width : 30px;
  height: 300px;
  margin: 0 auto;
  }
  .scrollbar-div::-webkit-scrollbar {
      /*滚动条整体样式*/
      width : 10px;  /*高宽分别对应横竖滚动条的尺寸*/
      height: 1px;
  }
  .scrollbar-div::-webkit-scrollbar-thumb {
      /*滚动条里面小方块*/
      border-radius: 10px;
      box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2);
      background   : #535353;
  }
  .scrollbar-div::-webkit-scrollbar-track {
      /*滚动条里面轨道*/
      box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2);
      border-radius: 10px;
      background   : #ededed;
  }

  .scrollbar-div2::-webkit-scrollbar {
      /*滚动条整体样式*/
      width : 10px;  /*高宽分别对应横竖滚动条的尺寸*/
      height: 1px;
  }
  .scrollbar-div2::-webkit-scrollbar-track {
      /*滚动条里面轨道*/
      box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2);
      border-radius: 10px;
      background   : #ededed;
  }
  .scrollbar-div2::-webkit-scrollbar-thumb {
      /*滚动条里面小方块*/
      border-radius: 10px;
      box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2);
      background   : #c2c2c2;
  }
  
  .fontsize21{font-size: 21px;}

    </style>
</head>

<body class="scrollbar-div" style="padding:3%">

  <div style="width: 100%;margin-bottom: 25px;">
    <div class="layui-btn-group" style="float: right;">
      <button type="button" class="layui-btn">导出</button>
      <a onclick="restore()" class="layui-btn">移动到指定笔记本</button>
      <!--<button type="button" class="layui-btn" onclick="openedit()">编辑</button>-->
      <a onclick="window.parent.editNote('/editmdnote/<<<.MDID>>>?title=<<<.Title>>>');" type="button" class="layui-btn layui-btn-normal" target="_parent">编辑</a>
      <a onclick="delmd()" type="button" class="layui-btn" style="background-color: red;color: #fff;" onclick="window.parent.createNoet();">删除</a>
    </div>
  </div>

    <div id="result" style="float: left;width: 98%;"></div>
<script type="text/javascript">
  //markDown转HTMl的方法
    function mdToHml(str){
        //先对容器初始化，在需要展示的容器中创建textarea隐藏标签，
        $("#result").html('<textarea id="appendTest" style="display:none;"></textarea>');
        var content=str;//获取需要转换的内容
        $("#appendTest").val(content);//将需要转换的内容加到转换后展示容器的textarea隐藏标签中
        //转换开始,第一个参数是上面的div的id
        editormd.markdownToHTML("result", {
            htmlDecode: "style,script,iframe", //可以过滤标签解码
            emoji: true,
            taskList:true,
            tex: true,               // 默认不解析
            flowChart:true,         // 默认不解析
            sequenceDiagram:true,  // 默认不解析
        });
    }

var text = '<<<.MDText>>>';
window.onload = function(){ 

  var errinfo = <<<.Error>>>;
  if(errinfo == 1){
    //alert("显示成功")
  }
  else if  (errinfo == 0){
    alert("后台错误")
  }
  else if  (errinfo == 2){
    alert("没有权限")
  }

  mdToHml(text);
  
}


function openedit(){
  window.location.href='/editmdnote/<<<.MDID>>>';  
}



function delmd(){
    $.ajax({
            url:  document.location.protocol+ "//" + window.location.host + '/delnote/<<<.MDID>>>',
            type:'get',
            async:true,//异步请求
            cache:false,
            success:function(rdata) {
                console.log(rdata);
                
                if(rdata.code == 1){
                  alert("删除成功")
                  window.parent.deletetab('<<<.MDID>>>');
                }else if (rdata.code == 2 || rdata.code == 0){
                  alert("删除失败"+rdata.data)
                }else{
                  alert("未知错误")
                }
               
            },
            //执行失败或错误的回调函数
            error:function(xhr) {
                alert("后台请求出错！");
                console.log(xhr);
            }
          });
}


//笔记本下拉菜单
function notes(){
    
    $.ajax({
            url:  document.location.protocol+ "//" + window.location.host + "/noteslist",
            type:'get',
            async:true,//异步请求
            cache:false,
            success:function(rdata) {
                console.log(rdata.data);
                var thisdata = rdata.data.notes;
                console.log(thisdata);
                $("#notes").empty();
                $("#notes").append('<option value="0">默认笔记本</option>');
                for(data in thisdata){
                    console.log(thisdata[data]);
                    var thisinfo = thisdata[data];
                    console.log(thisinfo["notes_name"]);
                    //'+thisdata["notes_id"]+'
                    
                    $("#notes").append('<option value="'+thisinfo["notes_id"]+'">'+thisinfo["notes_name"]+'</option>');

                }
            },
            //执行失败或错误的回调函数
            error:function(xhr) {
                alert("后台请求出错！");
                console.log(xhr);
            }
          });
}


var restoreLayer;

function restore(){
  
      

        var addDiv='<div id="addnote" >\
    <div class="layui-inline" style="margin-top: 50px;">\
            <label class="layui-form-label">选择笔记本</label>\
            <div class="layui-input-inline">\
              <select id="notes" name="city" lay-verify="" lay-search class="layui-input" style="width: 290px;">\</select>     \
            </div>\
          </div>\
        <div class="layui-inline" style="margin-top: 10px;">\
            <label class="layui-form-label"></label>\
            <div class="layui-input-inline">\
              <a onclick="restoretoNotes()" class="layui-btn layui-btn-primary" style="width: 280px;">添加</a>\
            </div>\
          </div>';

        

        layui.use("layer",function(){
            layer.ready(function(){
                var layer = layui.layer; 
                restoreLayer = layer.open({
                  type: 1,
                  title: '移动到指定笔记本', 
                  maxmin: true,
                  area: ['550px', '380px'],
                  content: addDiv
                });
                notes();
            });
        });
    }


function restoretoNotes(){
  var notes = $("#notes").val()
  $.ajax({
            url:  document.location.protocol+ "//" + window.location.host + '/restore/<<<.MDID>>>?notes='+notes,
            type:'get',
            async:true,//异步请求
            cache:false,
            success:function(rdata) {
                console.log(rdata);
                
                if(rdata.code == 1){
                  alert("移动成功")
                  window.parent.deletetab('<<<.MDID>>>');
                }else if (rdata.code == 2 || rdata.code == 0){
                  alert("移动失败"+rdata.data)
                }else{
                  alert("未知错误")
                }
               
            },
            //执行失败或错误的回调函数
            error:function(xhr) {
                alert("后台请求出错！");
                console.log(xhr);
            }
          });
}


</script>

</body>
</html>